package com.gitee.ywj1352.kafka.producer;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.util.concurrent.ListenableFuture;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class YWJKafkaProducer {

    @Autowired
    private KafkaTemplate kafkaTemplate;

    public String sendMessage(){
        for (int i = 0; i < 2; i++) {
            ListenableFuture future = kafkaTemplate.send("ywj_test_kafka", "test" + i);
        }
        return "OK";
    }

    @GetMapping("/send")
    public String send(){
      return  sendMessage();
    }
}
